<h1>Tạo booking mới</h1>

<h2>Thông tin khách hàng</h2>

<div id="select_customer">
    <?php echo $this->element('../bookings/select_customer', array('selected_customer' => $selected_customer)); ?>
</div>

<h2>Thông tin booking</h2>

<h3>Thông tin cơ bản</h3>

<?php echo $this->Form->create('Booking', array('action' => 'add')); ?>
<?php echo $this->Form->input('Action.do', array('type' => 'hidden', 'value' => 'add_booking')); ?>
<?php echo $this->Form->input('SelectedCustomer.code', array('type' => 'hidden', 'value' => '')); ?>
<div class="booking-info left" id="booking_info_left">
    <?php echo $this->element('../bookings/booking_info_left', array('locations' => $locations, 'hotels' => $hotels)); ?>
</div><!--.booking-info-->

<div class="booking-info center">
    <table class="table2">
        <tr>
            <td>Tình trạng <span class="compulsory">*</span></td>
            <td>
                <?php echo $this->Form->input('Booking.booking_status_id', array('type' => 'select', 'class' => 'dropdown', 'label' => false)); ?>
            </td>
        </tr>
        <tr>
            <td>Tổng đêm phòng</td>
            <td><span class="auto" id="total_days-label"></span>
            </td>
        </tr>
    </table>
        </div><!--.booking-info-->

<div class="booking-info right">
    <table class="table2">
        <tr>
            <td>Mã booking KS</td>
            <td><?php echo $this->Form->input('Booking.hotel_booking_code', array('type' => 'text', 'class' => 'textfield', 'label' => false)); ?></td>
        </tr>
        <tr>
            <td>Mã booking AL</td>
            <td>
                <?php echo $this->Form->input('Booking.alo_booking_code', array('type' => 'hidden', 'value' => $alo_booking_code)); ?>
                <?php //echo $this->element('barcode', array('data_to_encode' => $alo_booking_code)); ?>
                <span class="auto"><?php echo $alo_booking_code; ?></span>
            </td>
        </tr>
    </table>
</div><!--.booking-info-->

<br class="clr" />

<hr />

<h3>Thanh toán</h3>

<table class="table2 booking-payment">
    <tr>
        <td class="wide-spacing">
            <!-- Loại tiền &nbsp; -->
            <!-- <input id="usd" name="currency" type="radio" checked="checked" value="" /> <label for="usd">USD</label> &nbsp; -->
            <!-- <input id="vnd" name="currency" type="radio" value="" /> <label for="vnd">VND</label> -->
            <?php echo $this->Form->input('Booking.currency', array('type' => 'radio', 'options' => array('USD' => ' USD ', 'VND' => ' VND '), 'value' => !empty($this->data['Booking']['currency']) ? $this->data['Booking']['currency'] : 'USD', 'legend' => ' Loại tiền ')); ?>
        </td>

        <td class="wide-spacing">
            <?php echo $this->Form->input('Booking.vat', array('type' => 'checkbox', 'label' => ' Xuất VAT')); ?>
            <!-- <label for="vat">Xuất VAT</label> -->
        </td>

        <td class="wide-spacing">
            Tỷ giá ALO
            <?php echo $this->Form->input('Booking.alo_exchange_rate', array('type' => 'text', 'class' => 'textfield', 'label' => false, 'onchange' => 'process_booking_data();', 'onblur' => 'process_booking_data();', 'onkeyup' => 'process_booking_data();')); ?>
        </td>

        <td class="wide-spacing<?php echo $hide ?>">
            Tỷ giá KS
            <?php echo $this->Form->input('Booking.hotel_exchange_rate', array('type' => 'text', 'class' => 'textfield', 'label' => false, 'onchange' => 'process_booking_data();', 'onblur' => 'process_booking_data();', 'onkeyup' => 'process_booking_data();')); ?>
        </td>
    </tr>
</table>

<hr />

<h3>Thông tin chi tiết</h3>

<script type="text/javascript">
<?php
$max_key = 0;
if (!empty($this->data['BookingDetail']))
{
    foreach ($this->data['BookingDetail'] as $key => $value)
    {
        if ($max_key < $key)
        {
            $max_key = $key;
        }
    }
}
?>
var booking_detail_count = <?php echo $max_key; ?>;
var booking_detail_other_count = 0;

var currency = $('#BookingCurrencyUSD:checked').val() ? 'USD' : 'VND';
var alo_exchange_rate = $('#BookingAloExchangeRate').val();
var hotel_exchange_rate = $('#BookingHotelExchangeRate').val();

var booking_details = new Array();

function remove_field(index)
{
    booking_details[index] = null;
    process_booking_data();
}

function add_field(index)
{
    booking_details[index] = {
        "id" : index,
        "quantity" : '',
        "checkin_date" : '',
        "checkout_date" : '',
        "cost" : '',
        "days" : '',
        "price" : '',
        "original_cost" : '',
        "original_price" : ''
    };
    process_booking_data();
}

function add_field(index, quantity, checkin_date, checkout_date, cost, days, price, original_cost, original_price)
{
    booking_details[index] = {
        "id" : index,
        "quantity" : quantity ? quantity : '',
        "checkin_date" : checkin_date ? checkin_date : '',
        "checkout_date" : checkout_date ? checkout_date : '',
        "cost" : cost ? cost : '',
        "days" : days ? days : '',
        "price" : price ? price : '',
        "original_cost" : original_cost ? original_cost : '',
        "original_price" : original_price ? original_price : ''
    };
    process_booking_data();
}

function change_field_value(id, index)
{
    element = document.getElementById(id);
    if (element)
    {
        if (element.name == 'data[BookingDetail][' + index + '][quantity]')
        {
            booking_details[index].quantity = element.value;
        }
        else if (element.name == 'data[BookingDetail][' + index + '][checkin_date]')
        {
            booking_details[index].checkin_date = element.value;
        }
        else if (element.name == 'data[BookingDetail][' + index + '][checkout_date]')
        {
            booking_details[index].checkout_date = element.value;
        }
        else if (element.name == 'data[BookingDetail][' + index + '][cost]')
        {
            booking_details[index].cost = element.value;
        }
        else if (element.name == 'data[BookingDetail][' + index + '][original_cost]')
        {
            booking_details[index].original_cost = element.value;
        }

        currency = $('#BookingCurrencyUSD:checked').val() ? 'USD' : 'VND';
        alo_exchange_rate = $('#BookingAloExchangeRate').val();
        hotel_exchange_rate = $('#BookingHotelExchangeRate').val();

        days = process_date(index);
        quantity = $('#booking-detail-quantity-' + index).val();
        cost = $('#booking-detail-cost-' + index).val();
        original_cost = $('#booking-detail-original_cost-' + index).val();

        price = quantity * cost * days;
        original_price = quantity * original_cost * days;

        if (isNaN(price))
        {
            price = 0;
        }

        if (isNaN(original_price))
        {
            original_price = 0;
        }
        
        $('#price-label-' + index).html(number_format(price, 1, '.', ','));
        $('#booking-detail-price-' + index).val(price);

        $('#original_price-label-' + index).html(number_format(original_price, 1, '.', ','));
        $('#booking-detail-original_price-' + index).val(original_price);

        booking_details[index].price = price;
        booking_details[index].original_price = original_price;
    }

    process_booking_data()
}

function process_date(index)
{
    checkin_date = $('#booking-detail-checkin_date-' + index).val();
    checkin_date_parts = explode('/', checkin_date);
    if (checkin_date_parts == null)
    {
        return 0;
    }
    checkin_day = checkin_date_parts[0];
    checkin_month = checkin_date_parts[1] - 1;
    checkin_year = "20" + checkin_date_parts[2];
    checkin_js_date = new Date(checkin_year, checkin_month, checkin_day);

    checkout_date = $('#booking-detail-checkout_date-' + index).val();
    checkout_date_parts = explode('/', checkout_date);
    if (checkout_date_parts == null)
    {
        return 0;
    }
    checkout_day = checkout_date_parts[0];
    checkout_month = checkout_date_parts[1] - 1;
    checkout_year = "20" + checkout_date_parts[2];
    checkout_js_date = new Date(checkout_year, checkout_month, checkout_day);

    days_different = (checkout_js_date - checkin_js_date) / (24 * 60 * 60 * 1000);

    if (days_different != null && !isNaN(days_different) && days_different != 'undefined')
    {
        $('#days-label-' + index).html(days_different);
        $('#booking-detail-days-' + index).val(days_different);
        booking_details[index].days = days_different;
        if (days_different <= 0)
        {
            days_different = 1;
        }
        return days_different;
    }
    return 1;
}


function process_booking_data()
{
    currency = $('#BookingCurrencyUSD:checked').val() ? 'USD' : 'VND';
    alo_exchange_rate = $('#BookingAloExchangeRate').val();
    hotel_exchange_rate = $('#BookingHotelExchangeRate').val();

    total_vnd = 0;
    total_usd = 0;
    original_vnd = 0;
    original_usd = 0;
    profit_vnd = 0;
    profit_usd = 0;
    total_days = 0;
    for (var i in booking_details)
    {
        if (booking_details[i] != null)
        {
            index = booking_details[i].id;
            currency = $('#BookingCurrencyUSD:checked').val() ? 'USD' : 'VND';
            alo_exchange_rate = $('#BookingAloExchangeRate').val();
            hotel_exchange_rate = $('#BookingHotelExchangeRate').val();

            days = process_date(index);
            quantity = $('#booking-detail-quantity-' + index).val();
            cost = $('#booking-detail-cost-' + index).val();
            original_cost = $('#booking-detail-original_cost-' + index).val();

            price = quantity * cost * days;
            original_price = quantity * original_cost * days;

            if (isNaN(price))
            {
                price = 0;
            }

            if (isNaN(original_price))
            {
                original_price = 0;
            }

            $('#price-label-' + index).html(number_format(price, 1, '.', ','));
            $('#booking-detail-price-' + index).val(price);

            $('#original_price-label-' + index).html(number_format(original_price, 1, '.', ','));
            $('#booking-detail-original_price-' + index).val(original_price);

            booking_details[index].price = price;
            booking_details[index].original_price = original_price;
        }
        
        if (booking_details[i] != null)
        {
            total_days += parseInt(booking_details[i].days);
            if (isNaN(total_days))
            {
                total_days = 0;
            }
            if (currency == 'USD')
            {
                total_usd += parseInt(booking_details[i].price);
                if (isNaN(total_usd))
                {
                    total_usd = 0;
                }
                
                original_usd += parseInt(booking_details[i].original_price);
                if (isNaN(original_usd))
                {
                    original_usd = 0;
                }

                profit_usd = parseInt(total_usd - original_usd);
                if (isNaN(profit_usd))
                {
                    profit_usd = 0;
                }

                total_vnd = parseInt(total_usd * alo_exchange_rate);
                if (isNaN(total_vnd))
                {
                    total_vnd = 0;
                }
                
                original_vnd = parseInt(original_usd * hotel_exchange_rate);
                if (isNaN(original_vnd))
                {
                    original_vnd = 0;
                }

                profit_vnd = parseInt(total_vnd - original_vnd);
                if (isNaN(profit_vnd))
                {
                    profit_vnd = 0;
                }

            }
            else
            {
                total_vnd += parseInt(booking_details[i].price);
                if (isNaN(total_vnd))
                {
                    total_vnd = 0;
                }

                original_vnd += parseInt(booking_details[i].original_price);
                if (isNaN(original_vnd))
                {
                    original_vnd = 0;
                }

                profit_vnd = parseInt(total_vnd - original_vnd);
                if (isNaN(profit_vnd))
                {
                    profit_vnd = 0;
                }

                total_usd = parseInt(total_vnd / alo_exchange_rate);
                if (isNaN(total_usd))
                {
                    total_usd = 0;
                }

                original_usd = parseInt(original_vnd / hotel_exchange_rate);
                if (isNaN(original_usd))
                {
                    original_usd = 0;
                }

                profit_usd = parseInt(total_usd - original_usd);
                if (isNaN(profit_usd))
                {
                    profit_usd = 0;
                }
            }
        }
    }
    $('#total_days-label').html(total_days);

    $('#total_usd-label').html(number_format(total_usd, 1, '.', ','));
    $('#original_usd-label').html(number_format(original_usd, 1, '.', ','));
    $('#profit_usd-label').html(number_format(profit_usd, 1, '.', ','));

    $('#booking-total-total_usd').val(total_usd);
    $('#booking-total-original_usd').val(original_usd);
    $('#booking-total-profit_usd').val(profit_usd);

    $('#total_vnd-label').html(number_format(total_vnd, 1, '.', ','));
    $('#original_vnd-label').html(number_format(original_vnd, 1, '.', ','));
    $('#profit_vnd-label').html(number_format(profit_vnd, 1, '.', ','));

    $('#booking-total-total_vnd').val(total_vnd);
    $('#booking-total-original_vnd').val(original_vnd);
    $('#booking-total-profit_vnd').val(profit_vnd);

    calculate_remaining_hotel_charge()
}

function process_form_submit()
{
    var customer_code = $('#CustomerSelectedCode').val();
    if (customer_code && customer_code != 'undefined')
    {
        $('#SelectedCustomerCode').val(customer_code);
        return true;
    }
    else
    {
        alert('Xin vui lòng chọn khách hàng.');
        return false;
    }
}

function add_date_picker()
{
    $('input[class="textfield date autodate"]').datepicker({
        dateFormat: 'dd/mm/y',
        showOn: "both",
        buttonImage: "<?php echo $this->Html->url('/') . IMAGES_URL; ?>calendar.jpg",
        buttonImageOnly: true,
        onSelect: function (dateText, inst){
            date_value = $(this).val();
            date_id = $(this).attr('id');
            date_id = str_replace('booking-detail-checkin_date-', '', date_id);
            date_id = str_replace('booking-detail-checkout_date-', '', date_id);

            change_field_value($(this).attr('id'), date_id);
        }
    });
}

function calculate_remaining_hotel_charge()
{
    total_vnd = parseInt($('#booking-total-original_vnd').val());
    if (isNaN(total_vnd))
    {
        total_vnd = 0;
    }
    paid_vnd = parseInt($('#BookingHotelPrepaidAmount').val());
    if (isNaN(paid_vnd))
    {
        paid_vnd = 0;
    }
    remaining_vnd = parseInt(total_vnd - paid_vnd);
    if (isNaN(remaining_vnd))
    {
        remaining_vnd = 0;
    }
    $('#hotel_fullcharge_amount').html(number_format(remaining_vnd, 1, '.', ','));
}

$(document).ready(function (){
    $.datepicker.setDefaults( $.datepicker.regional[ "" ] );
    $( "#datepicker" ).datepicker( $.datepicker.regional[ "vi" ] );
    add_date_picker();
    $('#BookingDate').datepicker({ dateFormat: 'dd/mm/y' });
    $('#BookingAloExchangeRate').keyup(function (){
        change_field_value($(this).id, -1);
    });
    $('#BookingHotelExchangeRate').keyup(function (){
        change_field_value($(this).id, -1);
    });
    $('#BookingCurrencyUSD').change(function (){
        change_field_value($(this).id, -1);
    });
    $('#BookingCurrencyVND').change(function (){
        change_field_value($(this).id, -1);
    });
    $('input[class="textfield date"]').datepicker({
        dateFormat: 'dd/mm/y',
        showOn: "both",
        buttonImage: "<?php echo $this->Html->url('/') . IMAGES_URL; ?>calendar.jpg",
        buttonImageOnly: true
    });
    process_booking_data();
    $('#BookingHotelPrepaidAmount').keyup(function (){
        calculate_remaining_hotel_charge();
    });
});
</script>

<table class="table1 booking-detail">
    <tr>
        <th>Loại phòng</th>
        <th>Tiêu chuẩn</th>
        <th>SL</th>
        <th>Check in</th>
        <th>Check out</th>
        <th>Đơn giá</th>
        <th>Đêm</th>
        <th>Thành tiền</th>
        <th class="gross<?php echo $hide ?>">Giá gốc</th>
        <th class="gross<?php echo $hide ?>">Thành tiền</th>
        <th></th>
    </tr>
    <?php if (empty($this->data['BookingDetail'])): ?>
    <tr>
        <input name="data[BookingDetail][0][days]" type="hidden" id="booking-detail-days-0" />
        <input name="data[BookingDetail][0][price]" type="hidden" id="booking-detail-price-0" />
        <input name="data[BookingDetail][0][original_price]" type="hidden" id="booking-detail-original_price-0" />
        <td align="center"><input class="textfield room" name="data[BookingDetail][0][type]" id="booking-detail-type-0" type="text" /></td>
        <td align="center"><input class="textfield" name="data[BookingDetail][0][quality]" id="booking-detail-quality-0" type="text" /></td>
        <td align="center"><input class="textfield short" name="data[BookingDetail][0][quantity]" id="booking-detail-quantity-0" type="text" onkeyup="change_field_value(this.id, 0);" /></td>
        <td align="center"><input class="textfield date autodate" name="data[BookingDetail][0][checkin_date]" id="booking-detail-checkin_date-0" type="text" /></td>
        <td align="center"><input class="textfield date autodate" name="data[BookingDetail][0][checkout_date]" id="booking-detail-checkout_date-0" type="text" /></td>
        <td align="center">$ <input class="textfield" name="data[BookingDetail][0][cost]" id="booking-detail-cost-0" type="text" onkeyup="change_field_value(this.id, 0);" /></td>
        <td align="right" id="days-label-0"></td>
        <td align="right" id="price-label-0"></td>
        <td align="right" class="gross<?php echo $hide ?>">$ <input class="textfield" name="data[BookingDetail][0][original_cost]" id="booking-detail-original_cost-0" type="text" onkeyup="change_field_value(this.id, 0);" /></td>
        <td align="right" id="original_price-label-0" class="gross<?php echo $hide ?>"></td>
        <td align="right"><a href="javascript:" class="underline" onclick="$(this).parent().parent().remove();remove_field(0);">Xóa</a></td>
    </tr>
    <script type="text/javascript">
    add_field(0);
    </script>
    <?php else: ?>
    <?php foreach ($this->data['BookingDetail'] as $key => $value): ?>
    <tr>
        <input name="data[BookingDetail][<?php echo $key ?>][days]" type="hidden" id="booking-detail-days-<?php echo $key ?>" value="<?php echo $value['days'] ?>" />
        <input name="data[BookingDetail][<?php echo $key ?>][price]" type="hidden" id="booking-detail-price-<?php echo $key ?>" value="<?php echo $value['price'] ?>" />
        <input name="data[BookingDetail][<?php echo $key ?>][original_price]" type="hidden" id="booking-detail-original_price-<?php echo $key ?>" value="<?php echo $value['original_price'] ?>" />
        <td align="center"><input class="textfield room" name="data[BookingDetail][<?php echo $key ?>][type]" id="booking-detail-type-<?php echo $key ?>" value="<?php echo $value['type'] ?>" type="text" /></td>
        <td align="center"><input class="textfield" name="data[BookingDetail][<?php echo $key ?>][quality]" id="booking-detail-quality-<?php echo $key ?>" value="<?php echo $value['quality'] ?>" type="text" /></td>
        <td align="center"><input class="textfield short" name="data[BookingDetail][<?php echo $key ?>][quantity]" id="booking-detail-quantity-<?php echo $key ?>" value="<?php echo $value['quantity'] ?>" type="text" onkeyup="change_field_value(this.id, <?php echo $key ?>);" /></td>
        <td align="center"><input class="textfield date autodate" name="data[BookingDetail][<?php echo $key ?>][checkin_date]" id="booking-detail-checkin_date-<?php echo $key ?>" value="<?php echo $value['checkin_date'] ?>" type="text" /></td>
        <td align="center"><input class="textfield date autodate" name="data[BookingDetail][<?php echo $key ?>][checkout_date]" id="booking-detail-checkout_date-<?php echo $key ?>" value="<?php echo $value['checkout_date'] ?>" type="text" /></td>
        <td align="center">$ <input class="textfield" name="data[BookingDetail][<?php echo $key ?>][cost]" id="booking-detail-cost-<?php echo $key ?>" value="<?php echo $value['cost'] ?>" type="text" onkeyup="change_field_value(this.id, <?php echo $key ?>);" /></td>
        <td align="right" id="days-label-<?php echo $key ?>"><?php echo $value['days'] ?></td>
        <td align="right" id="price-label-<?php echo $key ?>"><?php echo is_numeric($value['price']) ? number_format($value['price'], 1, '.', ',') : $value['price'] ?></td>
        <td align="right" class="gross<?php echo $hide ?>">$ <input class="textfield" name="data[BookingDetail][<?php echo $key ?>][original_cost]" id="booking-detail-original_cost-<?php echo $key ?>" value="<?php echo $value['original_cost'] ?>" type="text" onkeyup="change_field_value(this.id, <?php echo $key ?>);" /></td>
        <td align="right" id="original_price-label-<?php echo $key ?>" class="gross<?php echo $hide ?>"><?php echo is_numeric($value['original_price']) ? number_format($value['original_price'], 1, '.', ',') : $value['original_price'] ?></td>
        <td align="right"><a href="javascript:" class="underline" onclick="$(this).parent().parent().remove();remove_field(<?php echo $key ?>);">Xóa</a></td>
    </tr>
    <?php endforeach; ?>
    <script type="text/javascript">
    <?php foreach ($this->data['BookingDetail'] as $key => $value): ?>
    add_field(<?php echo $key; ?>, '<?php echo $value['quantity']; ?>', '<?php echo $value['checkin_date']; ?>', '<?php echo $value['checkout_date']; ?>', '<?php echo $value['cost']; ?>', '<?php echo $value['days']; ?>', '<?php echo $value['price']; ?>', '<?php echo $value['original_cost']; ?>', '<?php echo $value['original_price']; ?>');
    <?php endforeach; ?>
    </script>
    <?php endif; ?>
    <tr>
        <td colspan="11">
            <a href="javascript:" class="underline" id="add-more">Thêm hàng mới</a>
        </td>
    </tr>
    <script type="text/javascript">
    $(document).ready(function() {
        $('#add-more').click(function(){
            booking_detail_count++;
            add_field(booking_detail_count);
            $(this).parent().parent().before(
            '<tr>' +
                '<input name="data[BookingDetail][' + booking_detail_count + '][days]" type="hidden" id="booking-detail-days-' + booking_detail_count + '" />' +
                '<input name="data[BookingDetail][' + booking_detail_count + '][price]" type="hidden" id="booking-detail-price-' + booking_detail_count + '" />' +
                '<input name="data[BookingDetail][' + booking_detail_count + '][original_price]" type="hidden" id="booking-detail-original_price-' + booking_detail_count + '" />' +
                '<td align="center"><input class="textfield room" name="data[BookingDetail][' + booking_detail_count + '][type]" id="booking-detail-type-' + booking_detail_count + '" type="text" /></td>' +
                '<td align="center"><input class="textfield" name="data[BookingDetail][' + booking_detail_count + '][quality]" id="booking-detail-quality-' + booking_detail_count + '" type="text" /></td>' +
                '<td align="center"><input class="textfield short" name="data[BookingDetail][' + booking_detail_count + '][quantity]" id="booking-detail-quantity-' + booking_detail_count + '" type="text" onkeyup="change_field_value(this.id, ' + booking_detail_count + ');" /></td>' +
                '<td align="center"><input class="textfield date autodate" name="data[BookingDetail][' + booking_detail_count + '][checkin_date]" id="booking-detail-checkin_date-' + booking_detail_count + '" type="text" /> <input type="hidden" /></td>' +
                '<td align="center"><input class="textfield date autodate" name="data[BookingDetail][' + booking_detail_count + '][checkout_date]" id="booking-detail-checkout_date-' + booking_detail_count + '" type="text" /> <input type="hidden" /></td>' +
                '<td align="center">$ <input class="textfield" name="data[BookingDetail][' + booking_detail_count + '][cost]" type="text" id="booking-detail-cost-' + booking_detail_count + '" onkeyup="change_field_value(this.id, ' + booking_detail_count + ');" /></td>' +
                '<td align="right" id="days-label-' + booking_detail_count + '"></td>' +
                '<td align="right" id="price-label-' + booking_detail_count + '"></td>' +
                '<td align="right" class="gross<?php echo $hide ?>">$ <input class="textfield" name="data[BookingDetail][' + booking_detail_count + '][original_cost]" id="booking-detail-original_cost-' + booking_detail_count + '" type="text" onkeyup="change_field_value(this.id, ' + booking_detail_count + ');" /></td>' +
                '<td align="right" id="original_price-label-' + booking_detail_count + '" class="gross<?php echo $hide ?>"></td>' +
                '<td align="right"><a href="javascript:" class="underline" onclick="$(this).parent().parent().remove();remove_field(' + booking_detail_count + ');">Xóa</a></td>' +
            '</tr>');
            add_date_picker();
            });
    });
    </script>
    <!--
    <tr class="heading">
        <th colspan="11">Loại khác</th>
    </tr>
    <tr>
        <td align="center"><input class="textfield room" name="input3" type="text" /></td>
        <td align="center"><input class="textfield" name="input2" type="text" /></td>
        <td align="center"><input class="textfield short" name="" type="text" /></td>
        <td align="center">&nbsp;</td>
        <td align="center">&nbsp;</td>
        <td align="center">$ <input class="textfield" name="" type="text" /></td>
        <td align="right"><input class="textfield short" name="input" type="text" /></td>
        <td align="right">-10</td>
        <td align="right" class="gross">$ <input class="textfield" name="" type="text" /></td>
        <td align="right" class="gross">0</td>
        <td align="right"><a href="javascript:" class="underline" onclick="$(this).parent().parent().remove();">Xóa</a></td>
    </tr>
    <tr>
        <td colspan="11">
            <a href="javascript:" class="underline" id="add-more-other">Thêm hàng mới</a>
        </td>
    </tr>
    -->
    <input name="data[BookingTotal][total_usd]" type="hidden" id="booking-total-total_usd" />
    <input name="data[BookingTotal][original_usd]" type="hidden" id="booking-total-original_usd" />
    <input name="data[BookingTotal][profit_usd]" type="hidden" id="booking-total-profit_usd" />
    <input name="data[BookingTotal][total_vnd]" type="hidden" id="booking-total-total_vnd" />
    <input name="data[BookingTotal][original_vnd]" type="hidden" id="booking-total-original_vnd" />
    <input name="data[BookingTotal][profit_vnd]" type="hidden" id="booking-total-profit_vnd" />
    <tr>
        <td colspan="6">Tổng tiền phòng</td>
        <td align="right">USD</td>
        <td align="right"><span class="highlight" id="total_usd-label"></span></td>
        <td class="gross<?php echo $hide ?>">&nbsp;</td>
        <td align="right" class="gross<?php echo $hide ?>" id="original_usd-label"></td>
        <td align="right" class="profit<?php echo $hide ?>" id="profit_usd-label">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="6">&nbsp;</td>
        <td align="right">VND</td>
        <td align="right"><span class="highlight" id="total_vnd-label"></span></td>
        <td class="gross<?php echo $hide ?>">&nbsp;</td>
        <td align="right" class="gross<?php echo $hide ?>" id="original_vnd-label"></td>
        <td align="right" class="profit<?php echo $hide ?>" id="profit_vnd-label"></td>
    </tr>
</table>

<h3>Bao gồm</h3>
<p class="pb20"><?php echo $this->Form->input('Booking.includes', array('type' => 'textarea', 'class' => 'ckeditor', 'label' => false)); ?></p>
<br />
<br class="clr" />

<div id="booking-cancel">
    <h3>Điều kiện hủy phòng</h3>

    <table class="table2">
        <tr>
            <td>Không phạt tiền</td>
            <td><?php echo $this->Form->input('Booking.cancel_0', array('type' => 'text', 'class' => 'textfield medium', 'label' => false, 'div' => false)); ?> &nbsp;ngày</td>
        </tr>
        <tr>
            <td>Phạt 50%</td>
            <td><?php echo $this->Form->input('Booking.cancel_50', array('type' => 'text', 'class' => 'textfield medium', 'label' => false, 'div' => false)); ?> &nbsp;ngày</td>
        </tr>
        <tr>
            <td>Phạt 100%</td>
            <td><?php echo $this->Form->input('Booking.cancel_100', array('type' => 'text', 'class' => 'textfield medium', 'label' => false, 'div' => false)); ?> &nbsp;ngày</td>
        </tr>
    </table>
</div>

<div id="booking-payment">
    <h3>Tình trạng thanh toán</h3>

    <table class="table1 booking-detail">
        <tr>
            <th>Tiến trình</th>
            <th>Ngày</th>
            <th>Tiền</th>
            <th>Phương thức</th>
            <th>Ghi chú</th>
        </tr>
        <tr>
            <td>Đặt cọc</td>
            <td><?php echo $this->Form->input('Booking.alo_prepaid_date', array('type' => 'text', 'class' => 'textfield date', 'label' => false)); ?></td>
            <td><?php echo $this->Form->input('Booking.alo_prepaid_amount', array('type' => 'text', 'class' => 'textfield', 'label' => false)); ?></td>
            <td>
                <?php echo $this->Form->input('Booking.alo_prepaid_payment_type_id', array('type' => 'select', 'class' => 'dropdown', 'label' => false)); ?>
            </td>
            <td><?php echo $this->Form->input('Booking.alo_prepaid_note', array('type' => 'text', 'class' => 'textfield long', 'label' => false)); ?></td>
        </tr>
        <tr>
            <td>Thu hết</td>
            <td><?php echo $this->Form->input('Booking.alo_fullcharge_date', array('type' => 'text', 'class' => 'textfield date', 'label' => false)); ?></td>
            <td><?php echo $this->Form->input('Booking.alo_fullcharge_amount', array('type' => 'text', 'class' => 'textfield', 'label' => false)); ?></td>
            <td>
                <?php echo $this->Form->input('Booking.alo_fullcharge_payment_type_id', array('type' => 'select', 'class' => 'dropdown', 'label' => false)); ?>
            </td>
            <td><?php echo $this->Form->input('Booking.alo_fullcharge_note', array('type' => 'text', 'class' => 'textfield long', 'label' => false)); ?></td>
        </tr>
        <tr>
            <td>KS thu</td>
            <td><?php echo $this->Form->input('Booking.hotel_charge_date', array('type' => 'text', 'class' => 'textfield date', 'label' => false)); ?></td>
            <td><?php echo $this->Form->input('Booking.hotel_charge_amount', array('type' => 'text', 'class' => 'textfield', 'label' => false)); ?></td>
            <td></td>
            <td><?php echo $this->Form->input('Booking.hotel_charge_note', array('type' => 'text', 'class' => 'textfield long', 'label' => false)); ?></td>
        </tr>
        <tr class="secondary<?php echo $hide ?>">
            <td>Deposit ks</td>
            <td><?php echo $this->Form->input('Booking.hotel_prepaid_date', array('type' => 'text', 'class' => 'textfield date', 'label' => false)); ?></td>
            <td><?php echo $this->Form->input('Booking.hotel_prepaid_amount', array('type' => 'text', 'class' => 'textfield', 'label' => false)); ?></td>
            <td>
                <?php echo $this->Form->input('Booking.hotel_prepaid_payment_type_id', array('type' => 'select', 'class' => 'dropdown', 'label' => false)); ?>
            </td>
            <td><?php echo $this->Form->input('Booking.hotel_prepaid_note', array('type' => 'text', 'class' => 'textfield long', 'label' => false)); ?></td>
        </tr>
        <tr class="secondar<?php echo $hide ?>">
            <td>T/T hết cho KS</td>
            <td><?php echo $this->Form->input('Booking.hotel_fullcharge_date', array('type' => 'text', 'class' => 'textfield date', 'label' => false)); ?></td>
            <td id="hotel_fullcharge_amount"></td>
            <td>
                <?php echo $this->Form->input('Booking.hotel_fullcharge_payment_type_id', array('type' => 'select', 'class' => 'dropdown', 'label' => false)); ?>
            </td>
            <td><?php echo $this->Form->input('Booking.hotel_fullcharge_note', array('type' => 'text', 'class' => 'textfield long', 'label' => false)); ?></td>
        </tr>
    </table>
</div>

<br class="clr" />

<div id="booking-submit">
    <?php echo $this->Form->submit('Tạo mới', array('class' => 'button', 'onclick' => "return process_form_submit()", 'div' => false)); ?>
    <?php echo $this->Form->submit('Hủy', array('class' => 'button', 'onclick' => "return back_to_index()", 'div' => false)); ?>
    <script type="text/javascript">
    function back_to_index()
    {
        window.location = '<?php echo $this->Html->url(array('controller' => 'bookings', 'action' => 'index')) ?>';
        return false;
    }
    </script>
</div>

<?php echo $this->Form->end(); ?>
<?php echo $this->Js->writeBuffer(); ?>